package com.alks.function.controller.biocontrol.webWork;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.entity.exception.ServiceErrorException;
import com.alks.function.data.dto.biocontrol.webwork.DelDetDto;
import com.alks.function.data.dto.biocontrol.webwork.DeliveryListDto;
import com.alks.function.service.biocontrol.webwork.IOrderDeliveryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author MS
 * @since 2025/3/21上午10:40
 */
@RestController
@ApiRestController("/OrdDlv")
@Api(value = "生控", tags = "订单交期分析")
@Slf4j
public class OrderDeliveryController {
    @Autowired
    private IOrderDeliveryService service;

    @WebLogger
    @PostMapping("/list")
    @ApiOperation(value = "首页明细", tags = "订单交期分析")
    public ResponseInfo list(@RequestParam String date) {
        List<DeliveryListDto> list = service.list(date);
        return ResponseInfo.ok(list);
    }

    @WebLogger
    @PostMapping("/detailList")
    @ApiOperation(value = "工艺节点", tags = "订单交期分析")
    public ResponseInfo detailList(@RequestParam String date,
                                   @RequestParam Integer type) {
        /*日期处理*/
        LocalDate startDate = null;
//        try{
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
            startDate = LocalDate.parse(date + "01", formatter);
//        }catch (Exception e){
//            throw new ServiceErrorException("日期格式异常");
//        }
        List<DelDetDto> delDetDtos = service.detailList(startDate, type);
        return ResponseInfo.ok(delDetDtos);
    }

}